package cn.com.wangkai.wangkaisiji.utils;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import cn.com.wangkai.wangkaisiji.R;
import cn.com.wangkai.wangkaisiji.bean.CartBean;

/**
 * Created by Administrator on 2016/11/16.
 */
public class CustomProgressDialog extends Dialog {


    private Context context;
    private static CustomProgressDialog customProgressDialog = null;

    public CustomProgressDialog(Context context) {
        super(context);
        this.context = context;
    }

    public CustomProgressDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    public static CustomProgressDialog createDialog(Context context) {
        customProgressDialog = new CustomProgressDialog(context, R.style.CustomProgressDialog);
        customProgressDialog.setContentView(R.layout.loading_dialog);
        customProgressDialog.getWindow().getAttributes().gravity= Gravity.CENTER;
        return customProgressDialog;
    }

    public void onWindowFocusChanged(boolean hasFocus){
        if (customProgressDialog==null){
            return;
        }
        ImageView imageView= (ImageView) customProgressDialog.findViewById(R.id.loadingImageView);
        AnimationDrawable animationDrawable= (AnimationDrawable) imageView.getBackground();
        animationDrawable.start();

    }
    public CustomProgressDialog setTitle(String strTitle){
        return customProgressDialog;
    }

    public CustomProgressDialog setMessage(String strMessage){
        TextView tvMsg= (TextView) customProgressDialog.findViewById(R.id.tipTextView);
        if (tvMsg != null){
            tvMsg.setText(strMessage);
        }
        return customProgressDialog;
    }

}
